package com.example.demo.controller;

import com.example.demo.model.TestExterCon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class ExternalController {
    @Autowired
    private RestTemplate restTemplate;

    @PostMapping("/external_controller")
    public ResponseEntity<String> externalController(@RequestBody TestExterCon testExterCon) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        MultiValueMap map = new LinkedMultiValueMap<>();
        map.add("userId",testExterCon.getUserId());
        map.add("gbCode",testExterCon.getGbCode());
        map.add("commitContent",testExterCon.getCommitContent());

        HttpEntity<MultiValueMap> entity = new HttpEntity<>(map, headers);

        ResponseEntity<String> response = restTemplate.exchange("http://localhost:9000/externalapi/gather/repeatedFusionFiveLevelCheck", HttpMethod.POST, entity, String.class);
        return response;
    }
}
